package com.digitalcollege.bean.custom;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @class: Response
 * @author: liyusheng
 * @description:
 * @date: 2022/12/17 20:48
 */
@ApiModel("响应实体")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Response<T> {

    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("消息")
    private String message;

    @ApiModelProperty("数据")
    private T data;

    public Response(ResponseCode code, T data) {
        this.code = code.getCode();
        this.message = code.getMessage();
    }

    public static <E> Response<E> of(ResponseCode code, E data) {
        return new Response<>(code, data);
    }

    public static <E> Response<E> of(Integer code, String message, E data) {
        return new Response<>(code, message, data);
    }

    public static <E> Response<E> success(E data) {
        return new Response<>(ResponseCode.SUCCESS, data);
    }

    public static <E> Response<E> success(E data, String message) {
        return new Response<>(ResponseCode.SUCCESS.getCode(), message, data);
    }
}
